//
//  DEWMessageHomeController.m
//  OtherDemo
//
//  Created by lianjie on 2018/7/24.
//  Copyright © 2018年 lianjie. All rights reserved.
//

#import "DEWMessageHomeController.h"
#import "DEWMessageTableCell.h"
#import "DEWMessageToolsTableCell.h"
#import "YBPopupMenu.h"
#import "JMDropMenu.h"
@interface DEWMessageHomeController ()<UITableViewDelegate,UITableViewDataSource,YBPopupMenuDelegate,JMDropMenuDelegate>
{
    ///多功能导航按钮
    UIButton *btnMenu;
    ///跳转类
    NSArray *classArray;
}

@property (nonatomic ,strong) UITableView *table;

///消息列表数据
@property (nonatomic ,strong) NSMutableArray *messageList;


@end

@implementation DEWMessageHomeController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title  = @"消息中心";
    ///加载数据
    [self loadData];
    ///初始化试图
    [self createView];
    ///通知、点赞、新朋友
    classArray = @[@"DEWNoticeListViewController",@"DEWLikeCommentController",@"DEWNewFriendViewController"];
}

#pragma mark ----requestData
-(void)loadData
{
    [KSHTTPSTool post:[KSService getAllMember] params:@{} success:^(id responseObject) {
       
        
        
    } failure:^(NSError *error) {
        
        
        
    }];
    
}
#pragma mark ---initView
-(void)createView
{
    [self.view addSubview:self.table];
    
    [self setUpNavItem];
    
}

///初始化navItem
- (void) setUpNavItem
{
    UIButton *btnF = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnF setTitle:@"通讯录" forState:UIControlStateNormal];
    btnF.frame = CGRectMake(0, 0, 20, 20);
    [btnF setTitleColor:UIColorFromRGB(0x333333) forState:UIControlStateNormal];
    btnF.titleLabel.font = [UIFont systemFontOfSize:15];
    btnF.tag = 1;
    [btnF addTarget:self action:@selector(navItemAction:) forControlEvents:UIControlEventTouchUpInside];
    ///多功能按钮
    UIButton *btnS = [UIButton buttonWithType:UIButtonTypeCustom];
    btnS.frame = CGRectMake(0, 0, 20, 20);
    [btnS setImage:[UIImage imageNamed:@"消息更多"] forState:UIControlStateNormal];
    btnS.tag = 2;
    btnMenu = btnS;
    [btnS addTarget:self action:@selector(navItemAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *itemF = [[UIBarButtonItem alloc]initWithCustomView:btnF];
    UIBarButtonItem *itemS = [[UIBarButtonItem alloc]initWithCustomView:btnS];
    
    self.navigationItem.rightBarButtonItems = @[itemS,itemF];
    
}

#pragma mark ---navAction
- (void)navItemAction:(UIButton *)sender
{
    if (sender.tag == 1) {
        ///通讯录
        BaseViewController *vc = [[NSClassFromString(@"DEWAddressListController") alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }else{
        ///多功能按键
        
//        CGRect frame = CGRectMake(DEWScreenWidth-15-14-133, NAVH, 133, 189);
        
//        JMDropMenu *menu = [JMDropMenu showDropMenuFrame:frame ArrowOffset:100 TitleArr:@[@"发起群聊",@"添加好友",@"发现群",@"扫一扫"] ImageArr:@[@"发起群聊",@"添加好友",@"发现群",@"扫一扫"] Type:JMDropMenuTypeQQ LayoutType:JMDropMenuLayoutTypeNormal RowHeight:45.0f Delegate:self];
//        menu.backgroundColor = [UIColor blackColor];
        
        YBPopupMenu *menu = [YBPopupMenu showAtPoint:CGPointMake(DEWScreenWidth-15-14, NAVH) titles:@[@"发起群聊",@"添加好友",@"发现群",@"扫一扫"] icons:@[@"发起群聊",@"添加好友",@"发现群",@"扫一扫"] menuWidth:133 delegate:self];
        menu.type = YBPopupMenuTypeDark;
        menu.arrowHeight = 10.0f;
        menu.arrowHeight = 4.0f;
        
    }
    
}
#pragma mark ---多功能按钮代理

//-(void)didSelectRowAtIndex:(NSInteger)index Title:(NSString *)title Image:(NSString *)image
//{
//
//}

-(void)ybPopupMenu:(YBPopupMenu *)ybPopupMenu didSelectedAtIndex:(NSInteger)index
{
    if (index == 0) {
        ///发起群聊
        BaseViewController *vc = [[NSClassFromString(@"DEWCountSafeViewController") alloc]init];
        
        [self.navigationController pushViewController:vc animated:YES];
        
    }else if (index == 1){
        ///添加好友
        BaseViewController *vc = [[NSClassFromString(@"DEWAddFriendViewController") alloc]init];
        
        [self.navigationController pushViewController:vc animated:YES];
        
    }else if (index == 2){
        ///发现群
        BaseViewController *vc = [[NSClassFromString(@"DEWFindGroupChatController") alloc]init];
        
        [self.navigationController pushViewController:vc animated:YES];
    }else{
       ///扫一扫
        
    }
    
    
}

#pragma mark ---tableView
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        
        return 3;
    }else{
        
        return self.messageList.count+5;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    NSInteger section = indexPath.section;
    NSInteger row = indexPath.row;
 
    NSString *identifier = [NSString stringWithFormat:@"cellIdentifier%ld_%ld",section,row];
    
    if (section == 0) {
        ///前三个固定cell
        
        DEWMessageToolsTableCell *toolCell = [[DEWMessageToolsTableCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        toolCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        NSString *imgStr = @"";
        
        if (row == 0) {
            imgStr = @"LJ系统消息";
            
            NSString *str01 = @"通知";
            NSString *str02 = @"（商城、认证、红花...）";
            
            NSString *str03 = [NSString stringWithFormat:@"%@%@",str01,str02];
            
            NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]initWithString:str03];
            [attStr setAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16 weight:UIFontWeightHeavy],NSForegroundColorAttributeName:UIColorFromRGB(0x333333)} range:NSMakeRange(0, str01.length)];
            [attStr setAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:UIColorFromRGB(0x999999)} range:NSMakeRange(str01.length, str02.length)];
            
            
            toolCell.titleLab.attributedText = attStr;
        }else if (row == 1){
            imgStr = @"LJ评论点赞";
            toolCell.titleLab.text = @"评论、点赞";
            
        }else{
            imgStr = @"LJ新朋友";
            toolCell.lj_lineWith = 0;
            toolCell.titleLab.text = @"新朋友";
        }
        
        toolCell.imageV.image = [UIImage imageNamed:imgStr];
        toolCell.imageV.backgroundColor = CellLineColor;
        return toolCell;
        
    }else{
        ///消息列表
        
        DEWMessageTableCell *messageCell = [tableView dequeueReusableCellWithIdentifier:identifier];
        
        if (messageCell == nil) {
            messageCell = [[DEWMessageTableCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
        
        messageCell.messageInfo = nil;///self.messageList[row]
        
        return messageCell;
    }
    
    
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 0) {
        return 10.0f;
    }else{
        return 0.001f;
    }
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.001f;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    if (indexPath.section == 0) {
        ///
        BaseViewController *vc = [[NSClassFromString(classArray[indexPath.row]) alloc]init];
        
        [self.navigationController pushViewController:vc animated:YES];
        
    }else{
        ///消息列表
        UIViewController *vc = [[NSClassFromString(@"DEGTheDiscountPushViewController") alloc]init];
        
        [self.navigationController pushViewController:vc animated:YES];
        
    }
    
}
#pragma mark --lazy
-(UITableView *)table
{
    if (!_table) {
        _table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, DEWScreenWidth, DEWScreenHeight-(NAVH)) style:UITableViewStyleGrouped];
        
        _table.delegate = self;
        
        _table.dataSource = self;
        
        _table.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _table;
    
}

-(NSMutableArray *)messageList
{
    if (!_messageList) {
        _messageList = [NSMutableArray array];
    }
    return _messageList;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
